<?php

/**
 * This is the model class for table "m_student_hinvoice".
 *
 * The followings are the available columns in table 'm_student_hinvoice':
 * @property integer $id
 * @property string $invoice_no
 * @property integer $student_transaction_type_id
 * @property string $bulk_no
 * @property string $invoice_date
 * @property integer $student_id
 * @property string $notes
 * @property string $ttl_invoice
 * @property string $ttl_disc
 * @property string $ttl_paid
 * @property string $ttl_cn
 * @property string $payment_type
 * @property integer $jurnal_id
 * @property integer $piutang_acc_id
 * @property string $invoice_type
 * @property string $input_date_time
 * @property integer $user_id
 * @property integer $is_active
 *
 * The followings are the available model relations:
 * @property MStudentDinvoice[] $mStudentDinvoices
 * @property MStudentDpayment[] $mStudentDpayments
 * @property MStudent $student
 * @property MStudentTransactionType $studentTransactionType
 * @property MHjurnal $jurnal
 * @property MCoa $piutangAcc
 * @property MStudentMonthlyFee[] $mStudentMonthlyFees
 */
class MStudentHinvoice extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_student_hinvoice';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('invoice_no, student_transaction_type_id, invoice_date, student_id, ttl_invoice, ttl_disc, ttl_paid, payment_type, jurnal_id, piutang_acc_id, invoice_type, input_date_time, user_id', 'required'),
			array('student_transaction_type_id, student_id, jurnal_id, piutang_acc_id, user_id, is_active', 'numerical', 'integerOnly'=>true),
			array('invoice_no, bulk_no, payment_type', 'length', 'max'=>100),
			array('ttl_invoice, ttl_disc, ttl_paid, ttl_cn', 'length', 'max'=>14),
			array('invoice_type', 'length', 'max'=>20),
			array('notes', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, invoice_no, student_transaction_type_id, bulk_no, invoice_date, student_id, notes, ttl_invoice, ttl_disc, ttl_paid, ttl_cn, payment_type, jurnal_id, piutang_acc_id, invoice_type, input_date_time, user_id, is_active', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'mStudentDinvoices' => array(self::HAS_MANY, 'MStudentDinvoice', 'invoice_id'),
			'mStudentDpayments' => array(self::HAS_MANY, 'MStudentDpayment', 'student_invoice_id'),
			'student' => array(self::BELONGS_TO, 'MStudent', 'student_id'),
			'studentTransactionType' => array(self::BELONGS_TO, 'MStudentTransactionType', 'student_transaction_type_id'),
			'jurnal' => array(self::BELONGS_TO, 'MHjurnal', 'jurnal_id'),
			'piutangAcc' => array(self::BELONGS_TO, 'MCoa', 'piutang_acc_id'),
			'mStudentMonthlyFees' => array(self::HAS_MANY, 'MStudentMonthlyFee', 'student_invoice_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'invoice_no' => 'Invoice No',
			'student_transaction_type_id' => 'Student Transaction Type',
			'bulk_no' => 'Bulk No',
			'invoice_date' => 'Invoice Date',
			'student_id' => 'Student',
			'notes' => 'Notes',
			'ttl_invoice' => 'Ttl Invoice',
			'ttl_disc' => 'Ttl Disc',
			'ttl_paid' => 'Ttl Paid',
			'ttl_cn' => 'Ttl Cn',
			'payment_type' => 'Payment Type',
			'jurnal_id' => 'Jurnal',
			'piutang_acc_id' => 'Piutang Acc',
			'invoice_type' => 'Invoice Type',
			'input_date_time' => 'Input Date Time',
			'user_id' => 'User',
			'is_active' => 'Is Active',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('invoice_no',$this->invoice_no,true);
		$criteria->compare('student_transaction_type_id',$this->student_transaction_type_id);
		$criteria->compare('bulk_no',$this->bulk_no,true);
		$criteria->compare('invoice_date',$this->invoice_date,true);
		$criteria->compare('student_id',$this->student_id);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('ttl_invoice',$this->ttl_invoice,true);
		$criteria->compare('ttl_disc',$this->ttl_disc,true);
		$criteria->compare('ttl_paid',$this->ttl_paid,true);
		$criteria->compare('ttl_cn',$this->ttl_cn,true);
		$criteria->compare('payment_type',$this->payment_type,true);
		$criteria->compare('jurnal_id',$this->jurnal_id);
		$criteria->compare('piutang_acc_id',$this->piutang_acc_id);
		$criteria->compare('invoice_type',$this->invoice_type,true);
		$criteria->compare('input_date_time',$this->input_date_time,true);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('is_active',$this->is_active);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MStudentHinvoice the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
